<%--
  Created by IntelliJ IDEA.
  User: DongZhengWei
  Date: 2018/11/5
  Time: 15:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">

	<div class="panel">
		<div class="panel-heading">
			<h3 class="panel-title">岗位信息</h3>
		</div>
		<div class="panel-body">
			<table id="post_table" cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered"></table>
		</div>
	</div>

</div>

<script>

	$(function(){
	    init_table_post();
	});

    function init_table_post(){
        var columns = [
	        {targets : 0, data : "id", title : "id", visible : false, orderable : false, searchable : false},
	        {targets : 1, data : "name", title : "岗位名称", visible : true, orderable : true, searchable : true},
	        {targets : 2, data : "description", title : "岗位描述", visible : true, orderable : true, searchable : true},
	        {targets : 3, title : "操作", visible : true, orderable : false, searchable : false, render : actRender},
        ];

        var buttons = [
	        {text : "新增岗位", className : "btn btn-primary", enabled : true, action : add_post}
        ];

        __init_dataTables("post_table",'<%=path%>/main/post/list',columns,buttons,false,true);
    }

    function actRender(data, type, row, meta){
        var id = row.id;
        data = '<button class="btn btn-default btn-xs" data-original-title="编辑" onclick="fn_post_edit(\'' + id + '\');"><i class="fa fa-pencil-square-o"> </i> 编辑</button> ';
        data += '<button class="btn btn-danger btn-xs" data-original-title="删除" onclick="fn_post_method(\'' + id + '\');"><i class="fa fa-trash-o"> </i> 删除</button>';
        return data;
    }

    //新建
	function add_post(e,dt,node,config){
        fn_post_edit();
	}

    //编辑
    function fn_post_edit(id) {
        __open_dialog_form('编辑岗位信息', '<%=path%>/main/post/input?keyId=' + id, function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();
                    $('#post_table').DataTable().ajax.reload();
                } else {
                    dialogRef.enableButtons();
                }
            };
            if (fn_post_input_save(callback) === false) {
                dialogRef.enableButtons();
            }
        });
    }

    //删除
    function fn_post_method(id) {
        __confirm_dialog(null, "确定要删除吗", function () {
            var url = '<%=path%>/main/post/delete';
            __ajax_post(url, {keyId : id}, function(data) {
                __toastr(data);
                if(data.state == 1) {
                    $("#post_table").jqGrid().setGridParam({datatype:'json'}).trigger("reloadGrid");
                }
            });
        });
    }

</script>